package com.esgov.chatbot.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.esgov.chatbot.entity.TProWoForm;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 工单DAO接口
 */
@Mapper
public interface TProWoFormDao extends BaseMapper<TProWoForm> {
    
    /**
     * 统计标签不为空的工单数
     * @return 标签不为空的工单数
     */
    @Select("SELECT COUNT(*) FROM pro_wo_form WHERE form_label IS NOT NULL AND form_label != ''")
    long countByLabelNotNull();
    
    /**
     * 统计黄牌+红牌的工单数
     * @return 预警工单数
     */
    @Select("SELECT COUNT(*) FROM pro_wo_form WHERE supervision = '黄牌' OR supervision = '红牌'")
    long countBySupervisionWarning();
    
    /**
     * 根据区域地址分组统计工单数
     * @return 区域统计数据
     */
    @Select("SELECT area, COUNT(*) as count FROM pro_wo_form WHERE area IS NOT NULL GROUP BY area")
    List<Map<String, Object>> countByAreaGroup();
    
    /**
     * 根据工单标题分组统计工单数
     * @return 话题量统计数据
     */
    @Select("SELECT title, COUNT(*) as count FROM pro_wo_form WHERE title IS NOT NULL GROUP BY title")
    List<Map<String, Object>> countByTitleGroup();
    
    /**
     * 根据工单事项分组统计工单数
     * @return 事件量统计数据
     */
    @Select("SELECT act_name, COUNT(*) as count FROM pro_wo_form WHERE act_name IS NOT NULL GROUP BY act_name")
    List<Map<String, Object>> countByActNameGroup();
}